/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package 解析.node.node;

import 解析.Matcher;

/**
 *
 * @author yanxi
 */
public class Neg extends Node {

    public Node cond;

    public Neg(Node cond) {
        this.cond = cond;
        getChildren().add(cond);
    }

    @Override
    public boolean match(Matcher matcher, int i, CharSequence seq) {
        int savedTo = matcher.to;
        boolean conditionMatched = false;

        // Relax transparent region boundaries for lookahead
        if (matcher.transparentBounds) {
            matcher.to = matcher.getTextLength();
        }
        try {
            if (i < matcher.to) {
                conditionMatched = !cond.match(matcher, i, seq);
            } else {
                // If a negative lookahead succeeds then more input
                // could cause it to fail!
                matcher.requireEnd = true;
                conditionMatched = !cond.match(matcher, i, seq);
            }
        } finally {
            // Reinstate region boundaries
            matcher.to = savedTo;
        }
        return conditionMatched && next.match(matcher, i, seq);
    } 
    
    @Override
    public String toString(){
        return cond.toString();
    }
}
